﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Microsoft.Xna.Framework.Graphics;

namespace game
{
    public class DefaultLightShader : Shader
    {
        public EffectParameter WVP { get; protected set; }
        public EffectParameter World { get; protected set; }
        public EffectParameter WorldInvT { get; protected set; }
        public EffectParameter EyePosW { get; protected set; }

        public EffectParameter DiffMat { get; protected set; }
        public EffectParameter AmbMat { get; protected set; }
        public EffectParameter SpecMat { get; protected set; }
        public EffectParameter SpecPower { get; protected set; }

        public EffectParameter DiffLight { get; protected set; }
        public EffectParameter AmbLight { get; protected set; }
        public EffectParameter SpecLight { get; protected set; }
        public EffectParameter MainLightDirW { get; protected set; }

        public EffectParameter DiffuseMap { get; protected set; }
        public EffectParameter NormalMap { get; protected set; }
        public EffectParameter BumpMap { get; protected set; }

        protected String normalMappingEffectTechName;
        protected EffectTechnique normalMappingEffectTech;

        protected String parallaxNormalMappingEffectTechName;
        protected EffectTechnique parallaxNormalMappingEffectTech;

        public DefaultLightShader()
        {
            effectFilename = "Effects\\phongtextured";
            effectTechName = "PhongTextured";
            normalMappingEffectTechName = "PhongNormalTextured";
            parallaxNormalMappingEffectTechName = "PhongParallaxNormalTextured";
        }

        public override void Initialize()
        {
            base.Initialize();

            WVP = Effect.Parameters["gWVP"];
            World = Effect.Parameters["gWorld"];
            WorldInvT = Effect.Parameters["gWorldInvT"];
            EyePosW = Effect.Parameters["gEyePosW"];

            DiffMat = Effect.Parameters["gDiffMat"];
            AmbMat = Effect.Parameters["gAmbMat"];
            SpecMat = Effect.Parameters["gSpecMat"];
            SpecPower = Effect.Parameters["gSpecPower"];

            DiffLight = Effect.Parameters["gDiffLight"];
            AmbLight = Effect.Parameters["gAmbLight"];
            SpecLight = Effect.Parameters["gSpecLight"];
            MainLightDirW = Effect.Parameters["gMainLightDirW"];

            DiffuseMap = Effect.Parameters["gTex"];
            NormalMap = Effect.Parameters["gTexNormal"];
            BumpMap = Effect.Parameters["gTexBump"];

            normalMappingEffectTech = Effect.Techniques[normalMappingEffectTechName];
            parallaxNormalMappingEffectTech = Effect.Techniques[parallaxNormalMappingEffectTechName];
        }

        public void SetNormalMapping(Texture2D normalMap)
        {
            Effect.CurrentTechnique = normalMappingEffectTech;
            NormalMap.SetValue(normalMap);
        }

        public void SetParallaxNormalMapping(Texture2D bumpMap, Texture2D normalMap)
        {
            Effect.CurrentTechnique = parallaxNormalMappingEffectTech;
            NormalMap.SetValue(normalMap);
            BumpMap.SetValue(bumpMap);
        }

        public void SetStandardTechnique()
        {
            Effect.CurrentTechnique = EffectTech;
        }
    }
}
